package com.nulstudio.cloud.account.mapper;

import com.nulstudio.cloud.common.entity.NulUserDetail;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Mapper for account-related operations.
 * @author nullsty
 * @since 2.0
 */
@Repository
@Mapper
public interface AccountMapper {

    /**
     * Fetch user information by ID.
     * @param uid ID of the user
     * @return information of the user if exists, null otherwise
     */
    @Nullable
    NulUserDetail getUserById(int uid);

    /**
     * Fetch user information by username.
     * @param name username of the user, must be non-null
     * @return information of the user if exists, null otherwise
     */
    @Nullable
    NulUserDetail getUserByUserName(@NonNull String name);

    /**
     * Check if the username has been registered.
     * @param userName username of the user
     * @return true if the user exist, false otherwise
     */
    boolean checkUserExistence(@NonNull String userName);

    int insertUser(@NonNull NulUserDetail user);

    /**
     * Fetch all users.
     * @return list of all users in system
     */
    @NonNull
    List<NulUserDetail> getUserList();

    /**
     * Update name of a user by UID.
     * @param uid uid of the user to update name
     * @param name new name for the user
     * @return columns changed after the operation
     */
    int updateName(int uid, @NonNull String name);
}
